package com.yixun.lbx.service.impl;

import com.yixun.lbx.entity.YxProBeeSwarm;
import com.yixun.lbx.mapper.farm.BeeSwarmMapper;
import com.yixun.lbx.service.BeeSwarmService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class BeeSwarmServiceImpl implements BeeSwarmService {

    private final BeeSwarmMapper beeSwarmMapper;

    public BeeSwarmServiceImpl(BeeSwarmMapper beeSwarmMapper) {
        this.beeSwarmMapper = beeSwarmMapper;
    }

    @Override
    public Integer getCount(HashMap<String, Object> map) {
        return beeSwarmMapper.getCount(map);
    }

    @Override
    public List<YxProBeeSwarm> getListByPage(HashMap<String, Object> map) {
        return beeSwarmMapper.getListByPage(map);
    }

    @Override
    public int addBeeSwarm(HashMap<String, Object> map) {
        map.put("addTime", getDate());
        return beeSwarmMapper.insertSelective(map);
    }

    @Override
    public int updateBeeSwarm(HashMap<String, Object> map) {
        map.put("updateTime", getDate());
        return beeSwarmMapper.updateByPrimaryKeySelective(map);
    }

    @Override
    public int deleteBeeSwarm(HashMap<String, Object> map) {
        map.put("updateTime", getDate());
        map.put("isDelete", -1);
        return beeSwarmMapper.updateByPrimaryKeySelective(map);
    }

    @Override
    public List<YxProBeeSwarm> getObjByArgs(YxProBeeSwarm beeSwarm) {
        return beeSwarmMapper.getObjByArgs(beeSwarm);
    }

    @Override
    public List<YxProBeeSwarm> getSearchListByPage(HashMap<String, String> map) {
        return beeSwarmMapper.getSearchListByPage(map);
    }

    private String getDate() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(new Date());
    }
}
